﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ChatForum.Domain;
using System.Data.Common;

namespace ChatForum.DAL
{
	static class DataMapper
	{
		#region Category

		internal static Category MapCategory(IDataRecord record)
		{
			return new Category()
			{
				ID = record.GetGuid(record.GetOrdinal("ID")),
				CreatedDate = record.GetDateTime(record.GetOrdinal("CreatedDate")),
				CreatedBy = record.GetString(record.GetOrdinal("CreatedBy")),
				ModifiedDate = record.GetDateTime(record.GetOrdinal("ModifiedDate")),
				ModifiedBy = record.GetString(record.GetOrdinal("ModifiedBy")),
				Name = record.GetString(record.GetOrdinal("name")),
				Description = record.GetString(record.GetOrdinal("description")),
				AgeRequirement = record.GetInt32(record.GetOrdinal("ageRequirement")),
			};
		}
		internal static IDbCommand CategoryInsertCommand(IDbCommand command, Category category)
		{
			command.CommandText = CategoryInsertQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = category.ID;
			command.Parameters.Add(id);

			IDbDataParameter name = command.CreateParameter();
			name.ParameterName = "@name";
			name.Direction = ParameterDirection.Input;
			name.DbType = DbType.String;
			name.Value = category.Name;
			command.Parameters.Add(name);

			IDbDataParameter description = command.CreateParameter();
			description.ParameterName = "@description";
			description.Direction = ParameterDirection.Input;
			description.DbType = DbType.String;
			description.Value = category.Description;
			command.Parameters.Add(description);

			IDbDataParameter ageRequirement = command.CreateParameter();
			ageRequirement.ParameterName = "@ageRequirement";
			ageRequirement.Direction = ParameterDirection.Input;
			ageRequirement.DbType = DbType.String;
			ageRequirement.Value = category.AgeRequirement;
			command.Parameters.Add(ageRequirement);

			IDbDataParameter createdDate = command.CreateParameter();
			createdDate.ParameterName = "@createdDate";
			createdDate.Direction = ParameterDirection.Input;
			createdDate.DbType = DbType.DateTime;
			createdDate.Value = DateTime.Now;
			command.Parameters.Add(createdDate);

			IDbDataParameter createdBy = command.CreateParameter();
			createdBy.ParameterName = "@createdBy";
			createdBy.Direction = ParameterDirection.Input;
			createdBy.DbType = DbType.String;
			createdBy.Value = category.CreatedBy;
			command.Parameters.Add(createdBy);

			IDbDataParameter modifiedDate = command.CreateParameter();
			modifiedDate.ParameterName = "@modifiedDate";
			modifiedDate.Direction = ParameterDirection.Input;
			modifiedDate.DbType = DbType.DateTime;
			modifiedDate.Value = DateTime.Now;
			command.Parameters.Add(modifiedDate);

			IDbDataParameter modifiedBy = command.CreateParameter();
			modifiedBy.ParameterName = "@modifiedBy";
			modifiedBy.Direction = ParameterDirection.Input;
			modifiedBy.DbType = DbType.String;
			modifiedBy.Value = category.ModifiedBy;
			command.Parameters.Add(modifiedBy);

			return command;
		}
		internal static IDbCommand CategoryDeleteCommand(IDbCommand command, Guid entityId)
		{
			command.CommandText = CategoryDeleteQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = entityId;
			command.Parameters.Add(id);

			return command;
		}
		internal static IDbCommand CategorySelectAllCommand(IDbCommand command)
		{
			command.CommandText = CategorySelectAllQueryString;
			return command;
		}
		internal static IDbCommand CategorySelectByIDCommand(IDbCommand command, Guid entityId)
		{
			command.CommandText = CategorySelectByIDQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = entityId;
			command.Parameters.Add(id);

			return command;
		}
		internal static IDbCommand CategoryModifyCommand(IDbCommand command, Category category)
		{
			command.CommandText = CategoryModifyQueryString;


			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = category.ID;
			command.Parameters.Add(id);

			IDbDataParameter name = command.CreateParameter();
			name.ParameterName = "@name";
			name.Direction = ParameterDirection.Input;
			name.DbType = DbType.String;
			name.Value = category.Name;
			command.Parameters.Add(name);

			IDbDataParameter description = command.CreateParameter();
			description.ParameterName = "@description";
			description.Direction = ParameterDirection.Input;
			description.DbType = DbType.String;
			description.Value = category.Description;
			command.Parameters.Add(description);

			IDbDataParameter ageRequirement = command.CreateParameter();
			ageRequirement.ParameterName = "@ageRequirement";
			ageRequirement.Direction = ParameterDirection.Input;
			ageRequirement.DbType = DbType.String;
			ageRequirement.Value = category.AgeRequirement;
			command.Parameters.Add(ageRequirement);

			IDbDataParameter modifiedDate = command.CreateParameter();
			modifiedDate.ParameterName = "@modifiedDate";
			modifiedDate.Direction = ParameterDirection.Input;
			modifiedDate.DbType = DbType.DateTime;
			modifiedDate.Value = DateTime.Now;
			command.Parameters.Add(modifiedDate);

			IDbDataParameter modifiedBy = command.CreateParameter();
			modifiedBy.ParameterName = "@modifiedBy";
			modifiedBy.Direction = ParameterDirection.Input;
			modifiedBy.DbType = DbType.String;
			modifiedBy.Value = category.ModifiedBy;
			command.Parameters.Add(modifiedBy);

			return command;
		}
		private readonly static string CategorySelectAllQueryString = "SELECT * FROM [Category]";
		private readonly static string CategorySelectByIDQueryString = "SELECT * FROM [Category] WHERE [id] = @id";
		private readonly static string CategoryDeleteQueryString = "DELETE FROM [Category] WHERE [id] = @id";
		private readonly static string CategoryInsertQueryString = @"INSERT INTO [ChatForum].[dbo].[Category]
           ([id]
           ,[name]
           ,[description]
           ,[ageRequirement]
           ,[createdDate]
           ,[createdBy]
           ,[modifiedDate]
           ,[modifiedBy])
     VALUES
           (@id
           ,@name
           ,@description
           ,@ageRequirement
           ,@createdDate
           ,@createdBy
           ,@modifiedDate
           ,@modifiedBy)";
		private readonly static string CategoryModifyQueryString = @"UPDATE [dbo].[Category]
           SET [name] = @name
              ,[description] = @description
              ,[ageRequirement] = @ageRequirement
              ,[modifiedDate] = @modifiedDate
              ,[modifiedBy] = @modifiedBy
         WHERE [id] = @id";
		#endregion


		#region User

		internal static User MapUser(IDataRecord record)
		{
			return new User()
			{
				ID = record.GetGuid(record.GetOrdinal("ID")),
				UserId = record.GetString(record.GetOrdinal("UserId")),
				Password = record.GetString(record.GetOrdinal("Password")),
				Status = record.GetBoolean(record.GetOrdinal("Status")),
				IsOnline = record.GetBoolean(record.GetOrdinal("IsOnline")),
				CreatedDate = record.GetDateTime(record.GetOrdinal("CreatedDate")),
				CreatedBy = record.GetString(record.GetOrdinal("CreatedBy")),
				ModifiedDate = record.GetDateTime(record.GetOrdinal("ModifiedDate")),
				ModifiedBy = record.GetString(record.GetOrdinal("ModifiedBy")),

				FirstName = record.GetString(record.GetOrdinal("firstName")),
				MiddleName = record.GetString(record.GetOrdinal("middleName")),
				LastName = record.GetString(record.GetOrdinal("lastName")),
				Sex = record.GetString(record.GetOrdinal("sex")),
				DateOfBirth = record.GetDateTime(record.GetOrdinal("dateOfBirth")),
				Country = record.GetString(record.GetOrdinal("country")),
				EmailId = record.GetString(record.GetOrdinal("emailId")),
				AlternateEmailId = record.GetString(record.GetOrdinal("alternateEmailId")),
				Role = (RoleENUM)record.GetInt32(record.GetOrdinal("role")),
				LastLogInTime = record.GetDateTime(record.GetOrdinal("lastLogInTime")),
				MobileNo = record.GetInt64(record.GetOrdinal("mobileNo")) + string.Empty,

			};
		}
		internal static IDbCommand UserInsertCommand(IDbCommand command, User user)
		{
			command.CommandText = UserInsertQueryString;

			IDbDataParameter firstName = command.CreateParameter();
			firstName.ParameterName = "@firstName";
			firstName.Direction = ParameterDirection.Input;
			firstName.DbType = DbType.String;
			firstName.Value = user.FirstName;
			command.Parameters.Add(firstName);

			IDbDataParameter middleName = command.CreateParameter();
			middleName.ParameterName = "@middleName";
			middleName.Direction = ParameterDirection.Input;
			middleName.DbType = DbType.String;
			middleName.Value = user.MiddleName;
			command.Parameters.Add(middleName);

			IDbDataParameter lastName = command.CreateParameter();
			lastName.ParameterName = "@lastName";
			lastName.Direction = ParameterDirection.Input;
			lastName.DbType = DbType.String;
			lastName.Value = user.LastName;
			command.Parameters.Add(lastName);

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = user.ID;
			command.Parameters.Add(id);

			IDbDataParameter sex = command.CreateParameter();
			sex.ParameterName = "@sex";
			sex.Direction = ParameterDirection.Input;
			sex.DbType = DbType.String;
			sex.Value = user.Sex;
			command.Parameters.Add(sex);

			IDbDataParameter dateOfBirth = command.CreateParameter();
			dateOfBirth.ParameterName = "@dateOfBirth";
			dateOfBirth.Direction = ParameterDirection.Input;
			dateOfBirth.DbType = DbType.Date;
			dateOfBirth.Value = user.DateOfBirth;
			command.Parameters.Add(dateOfBirth);

			IDbDataParameter country = command.CreateParameter();
			country.ParameterName = "@country";
			country.Direction = ParameterDirection.Input;
			country.DbType = DbType.String;
			country.Value = user.Country;
			command.Parameters.Add(country);

			IDbDataParameter emailId = command.CreateParameter();
			emailId.ParameterName = "@emailId";
			emailId.Direction = ParameterDirection.Input;
			emailId.DbType = DbType.String;
			emailId.Value = user.EmailId;
			command.Parameters.Add(emailId);

			IDbDataParameter alternateEmailId = command.CreateParameter();
			alternateEmailId.ParameterName = "@alternateEmailId";
			alternateEmailId.Direction = ParameterDirection.Input;
			alternateEmailId.DbType = DbType.String;
			alternateEmailId.Value = user.AlternateEmailId;
			command.Parameters.Add(alternateEmailId);

			IDbDataParameter userId = command.CreateParameter();
			userId.ParameterName = "@userId";
			userId.Direction = ParameterDirection.Input;
			userId.DbType = DbType.String;
			userId.Value = user.UserId;
			command.Parameters.Add(userId);

			IDbDataParameter password = command.CreateParameter();
			password.ParameterName = "@password";
			password.Direction = ParameterDirection.Input;
			password.DbType = DbType.String;
			password.Value = user.Password;
			command.Parameters.Add(password);

			IDbDataParameter role = command.CreateParameter();
			role.ParameterName = "@role";
			role.Direction = ParameterDirection.Input;
			role.DbType = DbType.Int32;
			role.Value = user.Role;
			command.Parameters.Add(role);

			IDbDataParameter status = command.CreateParameter();
			status.ParameterName = "@status";
			status.Direction = ParameterDirection.Input;
			status.DbType = DbType.Boolean;
			status.Value = user.Status;
			command.Parameters.Add(status);

			IDbDataParameter isOnline = command.CreateParameter();
			isOnline.ParameterName = "@isOnline";
			isOnline.Direction = ParameterDirection.Input;
			isOnline.DbType = DbType.Boolean;
			isOnline.Value = user.IsOnline;
			command.Parameters.Add(isOnline);

			IDbDataParameter lastLogInTime = command.CreateParameter();
			lastLogInTime.ParameterName = "@lastLogInTime";
			lastLogInTime.Direction = ParameterDirection.Input;
			lastLogInTime.DbType = DbType.DateTime;
			lastLogInTime.Value = user.LastLogInTime;
			command.Parameters.Add(lastLogInTime);

			IDbDataParameter mobileNo = command.CreateParameter();
			mobileNo.ParameterName = "@mobileNo";
			mobileNo.Direction = ParameterDirection.Input;
			mobileNo.DbType = DbType.Int64;
			mobileNo.Value = user.MobileNo;
			command.Parameters.Add(mobileNo);

			IDbDataParameter createdDate = command.CreateParameter();
			createdDate.ParameterName = "@createdDate";
			createdDate.Direction = ParameterDirection.Input;
			createdDate.DbType = DbType.DateTime;
			createdDate.Value = DateTime.Now;
			command.Parameters.Add(createdDate);

			IDbDataParameter createdBy = command.CreateParameter();
			createdBy.ParameterName = "@createdBy";
			createdBy.Direction = ParameterDirection.Input;
			createdBy.DbType = DbType.String;
			createdBy.Value = user.CreatedBy;
			command.Parameters.Add(createdBy);

			IDbDataParameter modifiedDate = command.CreateParameter();
			modifiedDate.ParameterName = "@modifiedDate";
			modifiedDate.Direction = ParameterDirection.Input;
			modifiedDate.DbType = DbType.DateTime;
			modifiedDate.Value = DateTime.Now;
			command.Parameters.Add(modifiedDate);

			IDbDataParameter modifiedBy = command.CreateParameter();
			modifiedBy.ParameterName = "@modifiedBy";
			modifiedBy.Direction = ParameterDirection.Input;
			modifiedBy.DbType = DbType.String;
            modifiedBy.Value = user.ModifiedBy;
			command.Parameters.Add(modifiedBy);


			return command;
		}
		internal static IDbCommand UserSelectAllCommand(IDbCommand command)
		{
			command.CommandText = UserSelectAllQueryString;
			return command;
		}
		internal static IDbCommand UserSelectByIDCommand(IDbCommand command, Guid entityId)
		{
			command.CommandText = UserSelectByIDQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = entityId;
			command.Parameters.Add(id);

			return command;
		}
		internal static IDbCommand UserDeleteCommand(IDbCommand command, Guid entityId)
		{
			command.CommandText = UserDeleteQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = entityId;
			command.Parameters.Add(id);

			return command;
		}
		internal static IDbCommand UserModifyCommand(IDbCommand command, User user)
		{
			command.CommandText = UserModifyQueryString;

			IDbDataParameter firstName = command.CreateParameter();
			firstName.ParameterName = "@firstName";
			firstName.Direction = ParameterDirection.Input;
			firstName.DbType = DbType.String;
			firstName.Value = user.FirstName;
			command.Parameters.Add(firstName);

			IDbDataParameter middleName = command.CreateParameter();
			middleName.ParameterName = "@middleName";
			middleName.Direction = ParameterDirection.Input;
			middleName.DbType = DbType.String;
			middleName.Value = user.MiddleName;
			command.Parameters.Add(middleName);

			IDbDataParameter lastName = command.CreateParameter();
			lastName.ParameterName = "@lastName";
			lastName.Direction = ParameterDirection.Input;
			lastName.DbType = DbType.String;
			lastName.Value = user.LastName;
			command.Parameters.Add(lastName);

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = user.ID;
			command.Parameters.Add(id);

			IDbDataParameter sex = command.CreateParameter();
			sex.ParameterName = "@sex";
			sex.Direction = ParameterDirection.Input;
			sex.DbType = DbType.String;
			sex.Value = user.Sex;
			command.Parameters.Add(sex);

			IDbDataParameter dateOfBirth = command.CreateParameter();
			dateOfBirth.ParameterName = "@dateOfBirth";
			dateOfBirth.Direction = ParameterDirection.Input;
			dateOfBirth.DbType = DbType.Date;
			dateOfBirth.Value = user.DateOfBirth;
			command.Parameters.Add(dateOfBirth);

			IDbDataParameter country = command.CreateParameter();
			country.ParameterName = "@country";
			country.Direction = ParameterDirection.Input;
			country.DbType = DbType.String;
			country.Value = user.Country;
			command.Parameters.Add(country);

			IDbDataParameter emailId = command.CreateParameter();
			emailId.ParameterName = "@emailId";
			emailId.Direction = ParameterDirection.Input;
			emailId.DbType = DbType.String;
			emailId.Value = user.EmailId;
			command.Parameters.Add(emailId);

			IDbDataParameter alternateEmailId = command.CreateParameter();
			alternateEmailId.ParameterName = "@alternateEmailId";
			alternateEmailId.Direction = ParameterDirection.Input;
			alternateEmailId.DbType = DbType.String;
			alternateEmailId.Value = user.AlternateEmailId;
			command.Parameters.Add(alternateEmailId);

			IDbDataParameter userId = command.CreateParameter();
			userId.ParameterName = "@userId";
			userId.Direction = ParameterDirection.Input;
			userId.DbType = DbType.String;
			userId.Value = user.UserId;
			command.Parameters.Add(userId);

			IDbDataParameter password = command.CreateParameter();
			password.ParameterName = "@password";
			password.Direction = ParameterDirection.Input;
			password.DbType = DbType.String;
			password.Value = user.Password;
			command.Parameters.Add(password);

			IDbDataParameter role = command.CreateParameter();
			role.ParameterName = "@role";
			role.Direction = ParameterDirection.Input;
			role.DbType = DbType.Int32;
			role.Value = user.Role;
			command.Parameters.Add(role);

			IDbDataParameter status = command.CreateParameter();
			status.ParameterName = "@status";
			status.Direction = ParameterDirection.Input;
			status.DbType = DbType.Boolean;
			status.Value = user.Status;
			command.Parameters.Add(status);

			IDbDataParameter isOnline = command.CreateParameter();
			isOnline.ParameterName = "@isOnline";
			isOnline.Direction = ParameterDirection.Input;
			isOnline.DbType = DbType.Boolean;
			isOnline.Value = user.IsOnline;
			command.Parameters.Add(isOnline);

			IDbDataParameter lastLogInTime = command.CreateParameter();
			lastLogInTime.ParameterName = "@lastLogInTime";
			lastLogInTime.Direction = ParameterDirection.Input;
			lastLogInTime.DbType = DbType.DateTime;
			lastLogInTime.Value = user.LastLogInTime;
			command.Parameters.Add(lastLogInTime);

			IDbDataParameter mobileNo = command.CreateParameter();
			mobileNo.ParameterName = "@mobileNo";
			mobileNo.Direction = ParameterDirection.Input;
			mobileNo.DbType = DbType.Int64;
			mobileNo.Value = user.MobileNo;
			command.Parameters.Add(mobileNo);

			IDbDataParameter modifiedDate = command.CreateParameter();
			modifiedDate.ParameterName = "@modifiedDate";
			modifiedDate.Direction = ParameterDirection.Input;
			modifiedDate.DbType = DbType.DateTime;
			modifiedDate.Value = DateTime.Now;
			command.Parameters.Add(modifiedDate);

			IDbDataParameter modifiedBy = command.CreateParameter();
			modifiedBy.ParameterName = "@modifiedBy";
			modifiedBy.Direction = ParameterDirection.Input;
			modifiedBy.DbType = DbType.String;
			modifiedBy.Value = user.ModifiedBy;
			command.Parameters.Add(modifiedBy);


			return command;
		}
		private readonly static string UserDeleteQueryString = "DELETE FROM User WHERE [id] = @id";
		private readonly static string UserSelectAllQueryString = "SELECT * FROM [User]";
		private readonly static string UserSelectByIDQueryString = "SELECT * FROM [User] WHERE [id] = @id";
		private readonly static string UserInsertQueryString = @"INSERT INTO [ChatForum].[dbo].[User]
           ([firstName]
           ,[middleName]
           ,[lastName]
           ,[id]
           ,[sex]
           ,[dateOfBirth]
           ,[country]
           ,[emailId]
           ,[alternateEmailId]
           ,[userId]
           ,[password]
           ,[role]
           ,[status]
           ,[isOnline]
           ,[lastLogInTime]
           ,[mobileNo]
           ,[createdDate]
           ,[createdBy]
           ,[modifiedDate]
           ,[modifiedBy])
     VALUES
           (@firstName
           ,@middleName
           ,@lastName	
           ,@id
           ,@sex
           ,@dateOfBirth
           ,@country
           ,@emailId
           ,@alternateEmailId
           ,@userId
           ,@password
           ,@role
           ,@status
           ,@isOnline
           ,@lastLogInTime
           ,@mobileNo
           ,@createdDate
           ,@createdBy
           ,@modifiedDate
           ,@modifiedBy)";

		private readonly static string UserModifyQueryString = @"UPDATE [dbo].[User]
           SET [firstName] = @firstName
              ,[middleName] = @middleName
              ,[lastName] = @lastName
              ,[sex] = @sex
              ,[dateOfBirth] = @dateOfBirth
              ,[country] = @country
              ,[emailId] = @emailId
              ,[alternateEmailId] = @alternateEmailId
              ,[userId] = @userId
              ,[password] = @password
              ,[role] = @role
              ,[status] = @status
              ,[isOnline] = @isOnline
              ,[lastLogInTime] = @lastLogInTime
              ,[mobileNo] = @mobileNo
              ,[modifiedDate] = @modifiedDate
              ,[modifiedBy] = @modifiedBy
         WHERE [id] = @id";
		#endregion


		#region Post

		internal static Post MapPost(IDataRecord record)
		{
			return new Post()
			{
				ID = record.GetGuid(record.GetOrdinal("ID")),
				CreatedDate = record.GetDateTime(record.GetOrdinal("CreatedDate")),
				CreatedBy = record.GetString(record.GetOrdinal("CreatedBy")),
				ModifiedDate = record.GetDateTime(record.GetOrdinal("ModifiedDate")),
				ModifiedBy = record.GetString(record.GetOrdinal("ModifiedBy")),
				Title = record.GetString(record.GetOrdinal("title")),
				Description = record.GetString(record.GetOrdinal("description")),
				ParentPost = record.GetGuid(record.GetOrdinal("parentPost")),
				ParentCategory = record.GetGuid(record.GetOrdinal("parentCategory")),
				Rating = record.GetInt32(record.GetOrdinal("rating")),
			};
		}
		internal static IDbCommand PostInsertCommand(IDbCommand command, Post post)
		{
			command.CommandText = PostInsertQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = post.ID;
			command.Parameters.Add(id);

			IDbDataParameter createdDate = command.CreateParameter();
			createdDate.ParameterName = "@createdDate";
			createdDate.Direction = ParameterDirection.Input;
			createdDate.DbType = DbType.DateTime;
			createdDate.Value = DateTime.Now;
			command.Parameters.Add(createdDate);

			IDbDataParameter createdBy = command.CreateParameter();
			createdBy.ParameterName = "@createdBy";
			createdBy.Direction = ParameterDirection.Input;
			createdBy.DbType = DbType.String;
			createdBy.Value = post.CreatedBy;
			command.Parameters.Add(createdBy);

			IDbDataParameter modifiedDate = command.CreateParameter();
			modifiedDate.ParameterName = "@modifiedDate";
			modifiedDate.Direction = ParameterDirection.Input;
			modifiedDate.DbType = DbType.DateTime;
			modifiedDate.Value = DateTime.Now;
			command.Parameters.Add(modifiedDate);

			IDbDataParameter modifiedBy = command.CreateParameter();
			modifiedBy.ParameterName = "@modifiedBy";
			modifiedBy.Direction = ParameterDirection.Input;
			modifiedBy.DbType = DbType.String;
			modifiedBy.Value = post.ModifiedBy;
			command.Parameters.Add(modifiedBy);

			IDbDataParameter title = command.CreateParameter();
			title.ParameterName = "@title";
			title.Direction = ParameterDirection.Input;
			title.DbType = DbType.String;
			title.Value = post.Title;
			command.Parameters.Add(title);

			IDbDataParameter description = command.CreateParameter();
			description.ParameterName = "@description";
			description.Direction = ParameterDirection.Input;
			description.DbType = DbType.String;
			description.Value = post.Description;
			command.Parameters.Add(description);

			IDbDataParameter parentCategory = command.CreateParameter();
			parentCategory.ParameterName = "@parentCategory";
			parentCategory.Direction = ParameterDirection.Input;
			parentCategory.DbType = DbType.Guid;
			parentCategory.Value = post.ParentCategory;
			command.Parameters.Add(parentCategory);

			IDbDataParameter parentPost = command.CreateParameter();
			parentPost.ParameterName = "@parentPost";
			parentPost.Direction = ParameterDirection.Input;
			parentPost.DbType = DbType.Guid;
			parentPost.Value = post.ParentPost;
			command.Parameters.Add(parentPost);

			IDbDataParameter rating = command.CreateParameter();
			rating.ParameterName = "@rating";
			rating.Direction = ParameterDirection.Input;
			rating.DbType = DbType.Int32;
			rating.Value = post.Rating;
			command.Parameters.Add(rating);

			return command;
		}
		internal static IDbCommand PostDeleteCommand(IDbCommand command, Guid entityId)
		{
			command.CommandText = PostDeleteQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = entityId;
			command.Parameters.Add(id);

			return command;
		}
		internal static IDbCommand PostSelectAllCommand(IDbCommand command)
		{
			command.CommandText = PostSelectAllQueryString;
			return command;
		}
		internal static IDbCommand PostSelectByIDCommand(IDbCommand command, Guid entityId)
		{
			command.CommandText = PostSelectByIDQueryString;

			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = entityId;
			command.Parameters.Add(id);

			return command;
		}
		internal static IDbCommand PostModifyCommand(IDbCommand command, Post post)
		{
			command.CommandText = PostModifyQueryString;


			IDbDataParameter id = command.CreateParameter();
			id.ParameterName = "@id";
			id.Direction = ParameterDirection.Input;
			id.DbType = DbType.Guid;
			id.Value = post.ID;
			command.Parameters.Add(id);

			IDbDataParameter modifiedDate = command.CreateParameter();
			modifiedDate.ParameterName = "@modifiedDate";
			modifiedDate.Direction = ParameterDirection.Input;
			modifiedDate.DbType = DbType.DateTime;
			modifiedDate.Value = DateTime.Now;
			command.Parameters.Add(modifiedDate);

			IDbDataParameter modifiedBy = command.CreateParameter();
			modifiedBy.ParameterName = "@modifiedBy";
			modifiedBy.Direction = ParameterDirection.Input;
			modifiedBy.DbType = DbType.String;
			modifiedBy.Value = post.ModifiedBy;
			command.Parameters.Add(modifiedBy);

			IDbDataParameter title = command.CreateParameter();
			title.ParameterName = "@title";
			title.Direction = ParameterDirection.Input;
			title.DbType = DbType.String;
			title.Value = post.Title;
			command.Parameters.Add(title);

			IDbDataParameter description = command.CreateParameter();
			description.ParameterName = "@description";
			description.Direction = ParameterDirection.Input;
			description.DbType = DbType.String;
			description.Value = post.Description;
			command.Parameters.Add(description);

			IDbDataParameter parentCategory = command.CreateParameter();
			parentCategory.ParameterName = "@parentCategory";
			parentCategory.Direction = ParameterDirection.Input;
			parentCategory.DbType = DbType.Guid;
			parentCategory.Value = post.ParentCategory;
			command.Parameters.Add(parentCategory);

			IDbDataParameter parentPost = command.CreateParameter();
			parentPost.ParameterName = "@parentPost";
			parentPost.Direction = ParameterDirection.Input;
			parentPost.DbType = DbType.Guid;
			parentPost.Value = post.ParentPost;
			command.Parameters.Add(parentPost);

			IDbDataParameter rating = command.CreateParameter();
			rating.ParameterName = "@rating";
			rating.Direction = ParameterDirection.Input;
			rating.DbType = DbType.Int32;
			rating.Value = post.Rating;
			command.Parameters.Add(rating);

			return command;
		}
		private readonly static string PostSelectAllQueryString = "SELECT * FROM [ChatForum].[dbo].[Post]";
		private readonly static string PostSelectByIDQueryString = "SELECT * FROM [ChatForum].[dbo].[Post] WHERE [id] = @id";
		private readonly static string PostDeleteQueryString = "DELETE FROM [ChatForum].[dbo].[Post] WHERE [id] = @id";
		private readonly static string PostInsertQueryString = @"INSERT INTO [ChatForum].[dbo].[Post]
           ([title]
           ,[description]
           ,[parentPost]
           ,[id]
           ,[parentCategory]
           ,[rating]
           ,[createdDate]
           ,[createdBy]
           ,[modifiedDate]
           ,[modifiedBy])
     VALUES
           (@title
           ,@description
           ,@parentPost
           ,@id
           ,@parentCategory
           ,@rating
           ,@createdDate
           ,@createdBy
           ,@modifiedDate
           ,@modifiedBy)";
		private readonly static string PostModifyQueryString = @"UPDATE [ChatForum].[dbo].[Post]
		   SET [title] = @title
			  ,[description] = @description
			  ,[parentPost] = @parentPost
			  ,[parentCategory] = @parentCategory
			  ,[rating] = @rating
			  ,[modifiedDate] = @modifiedDate
			  ,[modifiedBy] = @modifiedBy
		 WHERE [id] = @id";
		#endregion
	}
}
